$(function (){
    function bindCaptchaBtnClick(){
        $("#captcha-btn").click(function (event){
            let $this = $(this);
            let email = $("input[name='email']").val();
            if (!email){
                alert("请先输入邮箱");
                return;
            }
            $this.off('click')
            $.ajax('http://localhost:8000/test/email/?email='+email,{
                method:'GET',
                success:function (result){
                    console.log(result);
                },
                fail:function (error){
                    console.log(error);
                }
            })

            let counttime = 6
            let timer = setInterval(function (){
                if (counttime<=0){
                    $this.text('获取验证码');
                    clearInterval(timer);
                    bindCaptchaBtnClick()
                }
                else{
                    counttime --;
                    $this.text(counttime+'s')
                }
            },1000)
        })
    }
    bindCaptchaBtnClick()
})